﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LeadMaster.Helpers;
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Http.Formatting;
using System.Threading.Tasks;
using LeadMaster.Helpers;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace LeadMaster.Controllers
{
    public class DueDilController : Controller
    {

      public ActionResult FetchCompanies()
      {
        List<string> Results = new List<string>();
        HttpClient client = new HttpClient();
        string _address="http://api.duedil.com/v2/search/companies.json?query=tesco&api_key=gu244q88sdneswsex2nmtmzj";
        client.GetAsync(_address).ContinueWith(
          (requestTask) =>
            {
              HttpResponseMessage response = requestTask.Result;

              response.EnsureSuccessStatusCode();

              response.Content.ReadAsAsync<JsonTextReader>().ContinueWith(
                (readTask) =>
                  {
                    while (readTask.Result.Read())
                    {
                      Results.Add(string.Format("Token: {0}, Value: {1}", readTask.Result.TokenType, readTask.Result.ValueType));
                    }
                    
              });
      });
        return View();
      }
    }
}
